I want to use two drop down menus in my php application. All data should select from the database(Mysql) . Eg: 1st drop down(Fruit,Country,game) after selecting a item from the first drop down , second one should load perticular data from tha database. If i select Fruit then automatically load Mango,banana.etc to the second drop down. Could you please help me?
5 3575
We are here to help programmers with their PHP problems. And we can only help when we can see and work on the code you have developed.
So show it here and do not forget to enclose any code within the appropriate code tags!
Ronald
We are here to help programmers with their PHP problems. And we can only help when we can see and work on the code you have developed.
So show it here and do not forget to enclose any code within the appropriate code tags!
Ronald
This is my first dropdown(Thease are hard coded. no need to select from the database)
[HTML]<select name="name" id="name" >
<option value="Select" selected="selected">Select</option>
<option value="Fruit" >Fruit</option>
<option value="Country" >Country</option>
<option value="Game"> Game</option>
</select> [/HTML]
And second drop down should filled depend on the selected value in first dropdown.(get values from mysql database)
-
<!--
-
----------------------------
-
here i juz worked in a localhost.
-
database: demo1;
-
table: demo_table;
-
fields(demo_table)
-
item varchar(20);
-
list varchar(20);
-
example table data( i here used a simple table structure u can use a well one):
- item list
-
fruit Mango
-
fruit banana
-
Country India
-
Country USA
-
Country UK
-
----------------------------
-
-->
-
<html>
-
<head>
-
<title></title>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-
<script type="text/javascript">
-
function getItem(sel)
-
{
-
var itemCode = sel.options[sel.selectedIndex].value;
-
//alert(itemCode);
-
var url= "http://localhost/onchange1.php?item="+itemCode;
-
window.location=url;
-
-
}
-
</script>
-
</head>
-
-
<body>
-
-
<form action="" method="post">
-
<table>
-
<tr>
-
<td>Item </td>
-
<td><select id="item" name="item" onchange="getItem(this)">
-
<option value="">Select </option>
-
<option value="Fruit">Fruit</option>
-
<option value="Country" >Country</option>
-
</select>
-
</td>
-
</tr>
-
<tr>
-
<td>List </td>
-
<td><select id="item_list" name="item_list" >
-
<option value="">Select </option>
-
<?php
-
$i_code=$_REQUEST['item'];
-
-
$con = mysql_connect("localhost","root","");
-
mysql_select_db("demo1",$con);
-
-
$query="select list from demo_table where item='$i_code'";
-
$res=mysql_query($query);
-
$num=mysql_num_rows($res);
-
for($i=0;$i<$num;$i++)
-
{
-
$data=mysql_fetch_array($res);
-
$v=$data[0].$i;
-
echo "<option value='$data[0]'>".$data[0]."</option>";
-
}
-
?>
-
</select>
-
</td>
-
</tr>
-
</table>
-
</form>
-
</body>
-
</html>
-
it is a simplest method, and also u can use AJAX.
Atli 5,058
Expert 4TB
Hi sethupnr.
Please use [code] tags when posting your code examples. (See How to ask a question)
[code=html] ...HTML code goes here... [/code]
Thank you.
i have categories,then under each category,i want a sub category,all from database for example,category sells,then sub items and this is a menue in an html page from database,can u help plz
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Haines Brown |
last post by:
I've implemented the horizontal drop down menu discussed recently in
this newsgroup, and it works nicely under Galeon and Mozilla, but
not IE 5.0.
Here are the problems:
Under IE 5.0, the...
|
by: objectref |
last post by:
Hi to all,
i have an app that i allow a drag and drop operation of picture boxes on a
panel.
when i drop a picture box i do the following so my newly dropped picture box
will be able
to...
|
by: Axel Gillert |
last post by:
Hi!
I search a way (in c#) to integrate my own application into the
Windows-Desktop-Kontext-Menue (like ATI Hydravision, Catalyst Controlcenter
....),
so that a user can start it by clicking...
|
by: Don Wash |
last post by:
Hi There!
I have a Server-side Drop-down box in ASP.NET (VB) page. What do I do to
widen the Drop down box's Pull-Down list's width?
I'm not talking about the Drop-down box's width but the box...
|
by: Yoshitha |
last post by:
hi
I have 2 drop down lists in my application.1st list ontains itmes like
java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the
items like 50,60,70,80,90,100.
i will...
|
by: Gregc. |
last post by:
G'day
I was wondering if someone can explain the concept of 'returning a Char
from a Double' . For example, I have the following code:
char getGrade(double mark) {
if (mark>= 85)
return...
|
by: ssoffline |
last post by:
hi
i have an app in which i can drop objects onto a form and move them, it
consists of graphics (lines), i am using double buffering to avoid
filckering in the parent control which is a panel,but...
|
by: Bobc003 |
last post by:
Hi,
I'd like to put a double drop-down menu on my webpage and instead of a redirection to a new webpage, I'd like to display the result in a new section. I'm kind of stuck and I only have a triple...
|
by: geoman |
last post by:
Hello,
Anyone know of and example that does this?
Drop down 1 Select category
Apples
Peach
Drop down 2 populated from 1
Apple pie
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |